
package com.wutianyi.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Hello world!
 * 
 */
public class App {

	public static void main(String[] args) {

		ExecutorService executor =
				new ThreadPoolExecutor(1, 1, Long.MAX_VALUE, TimeUnit.NANOSECONDS,
						new LinkedBlockingQueue<Runnable>(1),
						new ThreadPoolExecutor.DiscardPolicy());
		executor.execute(new Runnable() {

			@Override
			public void run() {

				System.out.println(Thread.currentThread().getName() + " Begin Sleep!");
				try {
					Thread.sleep(5000);
				}catch(InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				System.out.println(Thread.currentThread().getName() + " End Sleep!");
			}
		});
		executor.execute(new Runnable() {

			@Override
			public void run() {

				System.out.println(Thread.currentThread().getName() + " Begin Sleep!");
				try {
					Thread.sleep(5000);
				}catch(InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				System.out.println(Thread.currentThread().getName() + " End Sleep!");
			}
		});executor.execute(new Runnable() {
			
			@Override
			public void run() {
		
				System.out.println(Thread.currentThread().getName() + " Begin Sleep!");
				try {
					Thread.sleep(5000);
				}catch(InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				System.out.println(Thread.currentThread().getName() + " End Sleep!");
			}
		});
	}
}
